// 转让管理
<template>
  <div class="transferManagement">
    <el-breadcrumb separator="/" class="bread-title">
      <el-breadcrumb-item :to="{ path: '/projectList' }">跟投项目管理</el-breadcrumb-item>
      <el-breadcrumb-item>转让管理</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="title">
      <span>*项目名称：</span>
      <span>{{projectName}}</span>
    </div>
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="转让人：">
        <el-input v-model="formInline.assignorName" placeholder="请输入转让人名称"></el-input>
      </el-form-item>
      <el-form-item label="接收人：">
        <el-input v-model="formInline.assigneeName" placeholder="请输入接收人名称"></el-input>
      </el-form-item>
      <el-form-item label="确定状态：">
        <el-select v-model="formInline.confirmationStatus" placeholder="全部">
          <el-option label="全部" value=""></el-option>
          <el-option label="待确认" value="0"></el-option>
          <el-option label="已确认" value="1"></el-option>
          <el-option label="已驳回" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态：">
        <el-select v-model="formInline.auditStatus" placeholder="全部">
          <el-option label="全部" value=""></el-option>
          <el-option label="未审核" value="0"></el-option>
          <el-option label="审核通过" value="1"></el-option>
          <el-option label="审核不通过" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit" id="monitorEnter">查询</el-button>
      </el-form-item>
    </el-form>
    <template>
      <el-table
        :data="tableData"
        border
        style="width: 100%">
        <el-table-column
          fixed
          align=center
          label="序号"
          type="index"
          width="80">
        </el-table-column>
        <el-table-column
          align=center
          prop="transferNo"
          label="转让单号"
          width="150">
        </el-table-column>
        <el-table-column
          align=center
          prop="investMoney"
          label="跟投金额（元）"
          width="150">
          <template slot-scope="scope">
            {{scope.row.investMoney | numFormat}}
          </template>
        </el-table-column>
        <el-table-column
          align=center
          prop="investNum"
          label="跟投份额"
          width="120">
        </el-table-column>
        <el-table-column
          align=center
          prop="assignorName"
          label="转让人姓名"
          width="150">
        </el-table-column>
        <el-table-column
          align=center
          prop="assigneeName"
          label="接收人姓名"
          width="150">
        </el-table-column>
        <el-table-column
          align=center
          prop="confirmationStatus"
          label="确认状态"
          width="150">
          <template slot-scope="scope">
            <span v-show="scope.row.confirmationStatus == 0">待确认</span>
            <span v-show="scope.row.confirmationStatus == 1">已确认</span>
            <span v-show="scope.row.confirmationStatus == 2">驳回</span>
          </template>
        </el-table-column>
        <el-table-column
          align=center
          prop="auditStatus"
          label="审核状态"
          width="150">
          <template slot-scope="scope">
            <span v-show="scope.row.auditStatus == 0">未审核</span>
            <span v-show="scope.row.auditStatus == 1">审核通过</span>
            <span v-show="scope.row.auditStatus == 2">审核不通过</span>
          </template>
        </el-table-column>
        <el-table-column
          align=center
          prop="createTime"
          label="更新时间"
          width="180">
        </el-table-column>
        <el-table-column
          align=center
          fixed="right"
          label="操作">
          <template slot-scope="scope">
            <el-button @click="handleReject(scope.row)" type="text" size="small" :disabled="scope.row.confirmationStatus == 0 && scope.row.auditStatus ==  0 ? false : true">驳回</el-button>
            <el-button @click="handleAudit(scope.row)" type="text" size="small" :disabled="scope.row.confirmationStatus == 1 && scope.row.auditStatus ==  0 ? false : true">审核</el-button>
            <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <div class="block">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="pageData.pageNum"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageData.pageSize"
        layout="total, sizes, prev, pager, next"
        :total="totalSize">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import api from '@/api/apiPath'
export default {
  name:'transferManagement',
  data(){
    return {
      totalSize:0,
      pageData:{
        pageSize:10,
        pageNum:1
      },
      formInline: {
        assignorName:'',
        assigneeName:'',
        confirmationStatus:'',
        auditStatus:''
      },
      tableData: [],
      id:'',
      projectName:''
    }
  },
  filters:{
    numFormat(val ){
      val += ''
      let x = val.split('.');
      let x1 = x[0] 
      let x2 = x.length > 1 ? '.' + x[1] : ''
      var rgx = /(\d+)(\d{3})/  
      while (rgx.test(x1)) {  
      x1 = x1.replace(rgx, '$1' + ',' + '$2')
      }
      return x1 + x2
    }
  },
  created(){
    this.getParams()
    this.onSubmit()
  },
  methods:{
    getParams(){
      if(this.$route.query.id){
        
        this.id = this.$route.query.id
        this.projectName = this.$route.query.projectName
        window.localStorage.setItem('projectId',this.$route.query.id)
        window.localStorage.setItem('projectName',this.$route.query.projectName)
      }else{
        this.id = window.localStorage.getItem('projectId')
        this.projectName = window.localStorage.getItem('projectName')
      }
    },
    onSubmit() {
      this.axios.post(api.selectPageList,{
        projectId:this.id,
        assignorName:this.formInline.assignorName,
        assigneeName:this.formInline.assigneeName,
        confirmationStatus:this.formInline.confirmationStatus,
        auditStatus:this.formInline.auditStatus,
        pageSize:this.pageData.pageSize,
        pageNum:this.pageData.pageNum,
      }).then((res)=>{
        console.log(res)
        this.tableData = res.data.data.list
        this.totalSize = res.data.data.total
      })
    },
    // 转让审核
    handleAudit(row){
      this.axios.get(api.checkOrderAmount + '/' + row.id).then((res)=>{
        console.log(res.data.code)
        if(res.data.code){
          this.$router.push({path:'/transferAudit',query:{
            id:row.id
          }})

        }
      })
    },
    // 驳回
    handleReject(row){
      this.$router.push({path:'/transferRejection',query:{
        id:row.id
      }})
    },
    // 查看
    handleClick(row) {
      console.log(row.id)
      this.$router.push({path:'/examineDetail',query:{
        id:row.id
      }})
    },
    handleSizeChange(val) {
      this.pageData.pageSize = val
      this.onSubmit()
    },
    handleCurrentChange(val) {
      this.onSubmit()
    }
  }
}
</script>

<style lang='stylus'>
.transferManagement{
  .bread-title{
    height:30px;
    font-size:16px;
  }
  .title{
    margin-bottom :50px;
    span {
      font-size :14px;
    }
  }
  .el-pagination{
    margin-top:20px;
  }
}
</style>
